//获取应用实例
var app = getApp();
Page({
    data: {
        //处理订单
        orderStatusDoingText:"处理订单",
        orderStatusFinishText:"订单完成",
        orderStatusClass: "icon_end",
        orderStatusAdd: "icon_doing",
        orderStatusToAdd: "icon_end",
        orderStatusTextClass: "",
        orderStatusExplainClass: "icon_order_accepted",
        orderStatusLineColour: "",
        isShowFootNav: false,
        isShowReEntry: false,
        isShowPage:false
    },
    onLoad: function (option) {
        var orderId = option.orderId;
        // var orderId = "201712251066595794";
        var pageObj = this;
        var opt = {
            url: app.globalData.host+"/wx/cn/detail.ajax",
            data: {
                'orderId':orderId,
                'userId': app.globalData.openId
            },
            sucFn:function (result) {
                var isShowReEntry = false;
                if(result.body.acceptRemark!=null&&result.body.acceptRemark.indexOf("未在选号前录入邮寄信息")>-1){
                    isShowReEntry = false;
                    result.body.statusDesc = "原因：未在选号前录入邮寄信息。请联系客服或请于15天后自行前往车管所领取号牌。客服热线：020-11183";
                }else if(result.body.status==4&&result.body.acceptRemark!=''){
                    isShowReEntry = result.body.acceptRemark!=null&&result.body.acceptRemark.indexOf("重复申请")>-1?false:true;
                    result.body.statusDesc = " 原因：" + result.body.acceptRemark + "。客服热线：020-11183";
                }

                pageObj.setData({
                    isShowPage:true,
                    "orderStatusText": result.body.statusName,  //订单的状态
                    "orderStatusCaptionText": result.body.statusDesc==null?result.body.progressName:result.body.statusDesc,   //订单的说明文字
                    "serviceFee":result.body.serviceFee|| 0,
                    "cardNbr":result.body.carNbr || "",
                    "acceptNbr":result.body.acceptNbr,
                    "carTypeName":result.body.carTypeName || "",
                    "name":result.body.name,
                    "address.contactName":result.body.address.contactName,
                    "address.cellNum":result.body.address.cellNum,
                    "address.fullAddr":result.body.address.fullAddr,
                    "orderId":result.body.orderId,
                    "progressName":result.body.progressName,
                    "progressTime":app.toYMDHMSDate(result.body.progressTime),
                    "createTime": app.toYMDHMSDate(result.body.createTime),
                    "completeTime": result.body.completeTime?app.toYMDHMSDate(result.body.completeTime):'',  //完成时间
                    "completeTimeText": result.body.status == 4?"关闭时间：":"完结时间："   //状态为8完成时间 4关闭时间
                });
                switch (result.body.status) {   //result.body.status
                    case 2: //支付成功
	                    // 进度状态 1  提交成功
	                    // 进度状态 2  受理成功
	                    // 进度状态 5  制牌成功
	                    switch (result.body.progressStatus){ //result.body.progressStatus
                        case 1:
                        //状态1是默认值
                            pageObj.setData({
                                orderStatusDoingText:"处理订单",
                                orderStatusFinishText:"订单完成",
                                orderStatusClass: "icon_doing",
                                orderStatusAdd: "icon_complete",
                                orderStatusToAdd: "",
                                orderStatusTextClass: "cx-time-now",
                                orderStatusExplainClass: "icon_order_accepting",
                                orderSideLineColour: "bg-color_blue",
                                orderStatusLineColour: ""
                            });
                        break;
                        case 2:
	                        pageObj.setData({
		                        orderStatusDoingText:"处理订单",
		                        orderStatusFinishText:"订单完成",
		                        orderStatusClass: "icon_complete",
		                        orderStatusAdd: "icon_doing",
		                        orderStatusToAdd: "",
		                        orderStatusTextClass: "cx-time-now",
		                        orderStatusExplainClass: "icon_order_succeed",
		                        orderSideLineColour: "bg-color_blue",
		                        orderStatusLineColour: ""
	                        });
                        break;
                        case 5:
	                        pageObj.setData({
                                orderStatusDoingText:"处理订单",
                                orderStatusFinishText:"订单完成",
                                orderStatusClass: "icon_doing",
                                orderStatusAdd: "icon_complete",
                                orderStatusToAdd: "",
                                orderStatusTextClass: "cx-time-now",
                                orderStatusExplainClass: "icon_order_succeed",
                                orderSideLineColour: "bg-color_blue",
                                orderStatusLineColour: ""
	                        });
                        break;
		                    default://其他
			                    break;
                      }
                      break;
                    case 3://退单申请中
	                    // 进度状态 3 受理失败
	                    // 进度状态 4  取消邮寄

                      switch (result.body.progressStatus){
                        case 3:
	                        pageObj.setData({
		                        orderStatusDoingText:"办理失败",
		                        orderStatusFinishText:"订单关闭",
		                        orderStatusClass: "icon_fail",
		                        orderStatusAdd: "icon_complete",
		                        orderSideLineColour: "bg-state_color_red",  //第一条线的颜色
		                        orderStatusToAdd: "icon_end",
		                        orderStatusTextClass: "state_color_red",
		                        orderStatusExplainClass: "icon_oeder_close_off",
		                        orderStatusLineColour: "bg-color",
	                        });
                        break;
                        case 4:
                            pageObj.setData({
                                orderStatusDoingText:"办理失败",
                                orderStatusFinishText:"订单关闭",
                                orderStatusClass: "icon_fail",
                                orderStatusAdd: "icon_complete",
                                orderSideLineColour: "bg-state_color_red",  //第一条线的颜色
                                orderStatusToAdd: "icon_end",
                                orderStatusTextClass: "state_color_red",
                                orderStatusExplainClass: "icon_oeder_close_off",
                                orderStatusLineColour: "bg-color"
                            });
                        break;
                      }
                        break;
                    case 4://订单关闭
                        pageObj.setData({
                            orderStatusDoingText:"办理失败",
	                          orderStatusFinishText:"订单关闭",
	                          orderStatusClass: "icon_failed",
	                          orderStatusAdd: "icon_complete",
	                          orderStatusToAdd: "icon_fail",
	                          orderStatusTextClass: "state_color_red",
                              orderStatusTextClassAdd: "state_color_red",
                            orderStatusExplainClass: "icon_oeder_close_off",
                            orderSideLineColour: "bg-color_blue",  //第一条线的颜色
                            orderStatusLineColour: "bg-color_red",
                            isShowReEntry: isShowReEntry
                        });
                        break;
                    case 8://订单已完成
                        pageObj.setData({
                            orderStatusDoingText:"处理订单",
                            orderStatusFinishText:"订单完成",
                            orderStatusClass: "icon_complete",
                            orderStatusAdd: "icon_complete",
                            orderStatusToAdd: "icon_doing",
                            orderStatusTextClass: "state_color_blue",
                            orderStatusTextClassAdd: "state_color_blue",
                            orderStatusExplainClass: "icon_order_succeed",
                            orderSideLineColour: "bg-color_blue",  //第一条线的颜色
                            orderStatusLineColour: "bg-color_blue"
                        });
                        break;
                    default://其他
                        break;
                }
            }
        };
        app.ajax(opt);
    },
    onHide:function () {
        app.removeStorageSync(app.globalData.globalData);
    },
    progressTap:function(e){
        var orderId = e.target.dataset.id;
        app.navigateTo({
            url: '../progress/progress?orderId='+orderId
        });
    },
    reEntryTap:function () {
        app.reLaunch({url: '../handle/handle?scene='+app.globalData.channelId});
    }
});
